package com.zueb.service.impl;

import com.zueb.mapper.UserInfoMapper;
import com.zueb.pojo.UserInfo;
import com.zueb.service.UserInfoService;
import com.zueb.util.SqlSessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

public class UserInfoServiceImpl implements UserInfoService {
    //1. 创建SqlSessionFactory 工厂对象
    SqlSessionFactory factory = SqlSessionFactoryUtils.getSqlSessionFactory();

    @Override
    public UserInfo getUserInfoByNumber(String number){
        //获取SqlSession对象
        SqlSession sqlSession = factory.openSession();
        //获取Mapper
        UserInfoMapper userInfoMapper = sqlSession.getMapper(UserInfoMapper.class);
        //调用方法
        UserInfo userInfo = userInfoMapper.getUserInfoByNumber(number);
        //释放资源
        sqlSession.close();

        return userInfo;
    }

    @Override
    public int updateUserInfoByNumber(UserInfo userInfo) {
        //获取SqlSession对象
        SqlSession sqlSession = factory.openSession(true);
        //获取Mapper
        UserInfoMapper userInfoMapper = sqlSession.getMapper(UserInfoMapper.class);
        //调用方法
        int flag = userInfoMapper.updateUserInfoByNumber(userInfo);
        //释放资源
        sqlSession.close();
        //返回修改是否成功
        return flag;

    }

}
